import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";
import _isUndefined from "lodash/isUndefined";
import _isEmpty from "lodash/isEmpty";

var _dec, _dec2, _class, _class2;

import React, { PureComponent } from 'react';
import { Modal, Form, Input, Select } from 'antd';
import { Bind } from 'lodash-decorators';
import Lov from 'components/Lov';
import Switch from 'components/Switch';
import intl from 'utils/intl';
import { CODE_UPPER } from 'utils/regExp';
var FormItem = Form.Item;
var Option = Select.Option;
/**
 * Form.Item 组件label、wrapper长度比例划分
 */

var formLayout = {
  labelCol: {
    span: 6
  },
  wrapperCol: {
    span: 16
  }
};
/**
 * 新建或编辑模态框数据展示
 * @extends {PureComponent} - React.PureComponent
 * @reactProps {Function} onAdd - 添加确定的回调函数
 * @reactProps {Function} onEdit - 编辑确定的回调函数
 * @reactProps {Object} serverTypeList - 服务类型
 * @reactProps {Object} tableRecord - 表格中信息的一条记录
 * @reactProps {Boolean} isCreate - 是否为新建账户
 * @reactProps {String} anchor - 模态框弹出方向
 * @return React.element
 */

var DetailModal = (_dec = Form.create({
  fieldNameProp: null
}), _dec2 = Bind(), _dec(_class = (_class2 = /*#__PURE__*/function (_PureComponent) {
  _inherits(DetailModal, _PureComponent);

  var _super = _createSuper(DetailModal);

  function DetailModal() {
    _classCallCheck(this, DetailModal);

    return _super.apply(this, arguments);
  }

  _createClass(DetailModal, [{
    key: "onOk",
    value: // 点击确认回调
    function onOk() {
      var _this$props = this.props,
          form = _this$props.form,
          onAdd = _this$props.onAdd,
          isCreate = _this$props.isCreate,
          isCopy = _this$props.isCopy,
          tableRecord = _this$props.tableRecord,
          onEdit = _this$props.onEdit;
      var _token = tableRecord._token,
          serverId = tableRecord.serverId,
          objectVersionNumber = tableRecord.objectVersionNumber;
      form.validateFields(function (err, values) {
        if (_isEmpty(err)) {
          if (isCreate || isCopy) {
            onAdd(values);
          } else {
            onEdit(_objectSpread({
              _token: _token,
              serverId: serverId,
              objectVersionNumber: objectVersionNumber
            }, values));
          }
        }
      });
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props2 = this.props,
          modalVisible = _this$props2.modalVisible,
          onCancel = _this$props2.onCancel,
          anchor = _this$props2.anchor,
          serverTypeList = _this$props2.serverTypeList,
          tableRecord = _this$props2.tableRecord,
          isCreate = _this$props2.isCreate,
          saving = _this$props2.saving,
          tenantRoleLevel = _this$props2.tenantRoleLevel,
          title = _this$props2.title,
          isCopy = _this$props2.isCopy;
      var getFieldDecorator = this.props.form.getFieldDecorator;
      return /*#__PURE__*/React.createElement(Modal, {
        destroyOnClose: true,
        title: isCopy ? intl.get('cpaas.common.button.copy').d('复制') : title,
        width: 520,
        onCancel: onCancel,
        onOk: this.onOk,
        visible: modalVisible,
        confirmLoading: saving,
        wrapClassName: "ant-modal-sidebar-".concat(anchor),
        transitionName: "move-".concat(anchor)
      }, /*#__PURE__*/React.createElement(Form, null, !tenantRoleLevel && /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get('cmsg.smsConfig.model.smsConfig.tenant').d('租户')
      }, formLayout), getFieldDecorator('tenantId', {
        rules: [{
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('cmsg.smsConfig.model.smsConfig.tenant').d('租户')
          })
        }],
        initialValue: tableRecord ? tableRecord.tenantId : ''
      })( /*#__PURE__*/React.createElement(Lov, {
        code: "CPFM.TENANT",
        textValue: tableRecord.tenantName,
        disabled: !isCreate
      }))), /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get('cmsg.common.view.accountCode').d('账户代码')
      }, formLayout), getFieldDecorator('serverCode', {
        rules: [{
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('cmsg.common.view.accountCode').d('账户代码')
          })
        }, {
          pattern: CODE_UPPER,
          message: intl.get('cpaas.common.validation.codeUpper').d('全大写及数字，必须以字母、数字开头，可包含“-”、“_”、“.”、“/”')
        }],
        initialValue: tableRecord ? tableRecord.serverCode : ''
      })( /*#__PURE__*/React.createElement(Input, {
        trim: true,
        typeCase: "upper",
        inputChinese: false,
        disabled: !isCreate
      }))), /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get('cmsg.common.view.accountName').d('账户名称')
      }, formLayout), getFieldDecorator('serverName', {
        rules: [{
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('cmsg.common.view.accountName').d('账户名称')
          })
        }],
        initialValue: tableRecord.serverName ? tableRecord.serverName : ''
      })( /*#__PURE__*/React.createElement(Input, null))), /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get('cmsg.smsConfig.model.smsConfig.signName').d('短信签名')
      }, formLayout), getFieldDecorator('signName', {
        rules: [{
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('cmsg.smsConfig.model.smsConfig.signName').d('短信签名')
          })
        }],
        initialValue: isCopy ? '' : tableRecord.signName
      })( /*#__PURE__*/React.createElement(Input, null))), /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get('cmsg.smsConfig.model.smsConfig.serverTypeCode').d('服务类型')
      }, formLayout), getFieldDecorator('serverTypeCode', {
        rules: [{
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('cmsg.smsConfig.model.smsConfig.serverTypeCode').d('服务类型')
          })
        }],
        initialValue: tableRecord.serverTypeCode ? tableRecord.serverTypeCode : ''
      })( /*#__PURE__*/React.createElement(Select, {
        allowClear: true
      }, serverTypeList && serverTypeList.map(function (item) {
        return /*#__PURE__*/React.createElement(Option, {
          value: item.value,
          key: item.value
        }, item.meaning);
      })))), /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get('cmsg.smsConfig.model.smsConfig.EndPoint').d('EndPoint')
      }, formLayout), getFieldDecorator('endPoint', {
        rules: [{
          required: false,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('cmsg.smsConfig.model.smsConfig.EndPoint').d('EndPoint')
          })
        }],
        initialValue: isCopy ? '' : tableRecord.endPoint
      })( /*#__PURE__*/React.createElement(Input, null))), /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get('cmsg.smsConfig.model.smsConfig.AccessKey').d('AccessKey')
      }, formLayout), getFieldDecorator('accessKey', {
        rules: [{
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('cmsg.smsConfig.model.smsConfig.AccessKey').d('AccessKey')
          })
        }],
        initialValue: isCopy ? '' : tableRecord.accessKey
      })( /*#__PURE__*/React.createElement(Input, null))), /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get('cmsg.smsConfig.model.smsConfig.accessKeySecret').d('AccessKeySecret')
      }, formLayout), getFieldDecorator('accessKeySecret', {
        rules: [{
          required: false,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('cmsg.smsConfig.model.smsConfig.accessKeySecret').d('AccessKeySecret')
          })
        }, {
          max: 110,
          message: intl.get('cpaas.common.validation.max', {
            max: 110
          })
        }],
        initialValue: tableRecord.accessKeySecret ? tableRecord.accessKeySecret : ''
      })( /*#__PURE__*/React.createElement(Input, {
        type: "password",
        placeholder: !isCreate ? intl.get('cpaas.common.validation.notChange').d('未更改') : ''
      }))), /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get('cpaas.common.status.enable').d('启用')
      }, formLayout), getFieldDecorator('enabledFlag', {
        initialValue: _isUndefined(tableRecord.enabledFlag) ? 1 : tableRecord.enabledFlag
      })( /*#__PURE__*/React.createElement(Switch, null)))));
    }
  }]);

  return DetailModal;
}(PureComponent), (_applyDecoratedDescriptor(_class2.prototype, "onOk", [_dec2], Object.getOwnPropertyDescriptor(_class2.prototype, "onOk"), _class2.prototype)), _class2)) || _class);
export { DetailModal as default };